﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class DanTocDAO
    {
        public static List<DanTocDTO> dsDanToc()//collection Mang chua doi tuong-------------- 
        {
            List<DanTocDTO> dsDanToc = new List<DanTocDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM DanToc order by (tenDanToc) asc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DanTocDTO t = new DanTocDTO();

                t.TenDanToc = dt.Rows[i]["tenDanToc"].ToString();
                t.MaDanToc  = Int32.Parse(dt.Rows[i]["maDanToc"].ToString());

                dsDanToc.Add(t);
            }
            return dsDanToc;
        }
        //ham them 
        public static bool themDanToc(DanTocDTO t)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO DanToc(tenDanToc) VALUES(N'" + t.TenDanToc  + "')");
        }
        //ham xoa 
        public static bool xoaDanToc(DanTocDTO t)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM DanToc WHERE maDanToc=" + t.MaDanToc + " ");
        }
        //ham cap nhat 
        public static bool capNhatDanToc(DanTocDTO t)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE DanToc set tenDanToc=N'" + t.TenDanToc + "' WHERE maDanToc=" + t.MaDanToc + " ");
        }
    }
}
